package com.zhuangjie.shop.controller;


import com.zhaungjie.base.conduit.R;
import com.zhuangjie.mvc.validator.valid.DefaultGroup;
import com.zhuangjie.mvc.validator.valid.UpdateGroup;
import com.zhuangjie.shop.entity.ShopBusinessRules;
import com.zhuangjie.shop.service.ShopBusinessRulesService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhuangjie
 * @since 2023-11-16
 */
@RestController
@RequestMapping("/shop-business-rules")
public class ShopBusinessRulesController {

    @Autowired
    private ShopBusinessRulesService shopBusinessRulesService;

    @GetMapping("/shop-rules")
    @ApiOperation("查询店铺的经营时间规则列表")
    public R listShopRules() {
        return R.require(List.class,shopBusinessRulesService.listShopRules());
    }

    @PostMapping("/add")
    @ApiOperation("添加店铺经营时间规则")
    public R addShopBusinessTimeRule(@Validated({DefaultGroup.class}) @RequestBody ShopBusinessRules shopBusinessRules) {
        return R.capture(()->shopBusinessRulesService.saveOrUpdateShopBusinessTimeRule(shopBusinessRules));
    }

    @PutMapping("/update")
    @ApiOperation("更新店铺经营时间规则")
    public R updateShopBusinessTimeRule(@Validated({DefaultGroup.class, UpdateGroup.class}) @RequestBody ShopBusinessRules shopBusinessRules) {
        return R.capture(()->shopBusinessRulesService.saveOrUpdateShopBusinessTimeRule(shopBusinessRules));
    }

    @GetMapping("/{ruleId}")
    @ApiOperation("获取指定的店铺规则信息")
    public R getShopBusinessTimeRuleById(@PathVariable("ruleId") Long ruleId) {
        return R.require(ShopBusinessRules.class,shopBusinessRulesService.getShopBusinessRuleById(ruleId));
    }
    @DeleteMapping("/{ruleId}")
    @ApiOperation("删除指定的店铺规则信息")
    public R removeShopBusinessTimeRuleById(@PathVariable("ruleId") Long ruleId) {
        return R.capture(()->shopBusinessRulesService.removeShopBusinessRuleById(ruleId));
    }


}

